import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        name: "Home",
        component: () => import("@/views/Home"),
    },
    {
        path: "/notice/detail",
        name: "NoticeDetail",
        component: () => import("@/views/notice/NoticeDetail.vue"),
        meta: {title: "公告详情"},
    },
    {
        path: "/competition-information",
        name: "CompetitionInformation",
        component: () => import("@/views/CompetitionInformation/CompetitionInformation"),
        meta: {title: "竞赛信息"},
    },
    {
        path: "/mock-match",
        name: "MockMatch",
        component: () => import("@/views/MockMatch/MockMatch.vue"),
        meta: {title: "模拟赛场"},
    },
    {
        path: "/study-guide",
        name: "StudyGuide",
        component: () => import("@/views/StudyGuide/StudyGuide.vue"),
        meta: {title: "学习指导"},
    },
    {
        path: "/study-guide/create",
        name: "StudyGuideCreate",
        component: () => import("@/views/StudyGuide/Create.vue"),
        meta: {title: "学习指导"},
    },
    {
        path: "/study-guide/detail",
        name: "StudyGuideDetail",
        component: () => import("@/views/StudyGuide/Detail.vue"),
        meta: {title: "学习指导"},
    },
    {
        path: "/courseware",
        name: "Courseware",
        component: () => import("@/views/Courseware/Courseware.vue"),
        meta: {title: "电子课件"},
    },
    {
        path: "/practice-test",
        name: "PracticeTest",
        component: () => import("@/views/PracticeTest/PracticeTest.vue"),
        meta: {title: "练习与测试"},
    },
    {
        path: "/program-detail",
        name: "ProgramDetail",
        component: () => import("@/views/program/ProgramDetail.vue"),
        meta: {title: "题目详情"},
    },
    {
        path: "/register",
        name: "register",
        component: () => import("@/views/auth/Register"),
        meta: {title: "注册"},
    },
    // 登录
    {
        name: "login",
        path: "/login",
        component: () => import("@/views/auth/Login"),
        meta: {title: "登录"},
    },
    // 发布
    {
        name: "post-create",
        path: "/post/create",
        component: () => import("@/views/post/Create"),
        meta: {title: "信息发布", requireAuth: true},
    },
    // 编辑
    {
        name: 'topic-edit',
        path: '/topic/edit/:id',
        component: () => import('@/views/post/Edit'),
        meta: {
            title: '编辑',
            requireAuth: true
        }
    },
    // 详情
    {
        name: "post-detail",
        path: "/post/:id",
        component: () => import("@/views/post/Detail"),
        meta: {title: "详情"},
    },
    {
        name: 'tag',
        path: '/tag/:name',
        component: () => import('@/views/tag/Tag'),
        meta: {title: '主题列表'}
    },
    // 检索
    {
        name: 'search',
        path: '/search',
        component: () => import('@/views/Search'),
        meta: {title: '检索'}
    },
    // 用户主页
    {
        name: 'user',
        path: '/member/:username/home',
        component: () => import('@/views/user/Profile'),
        meta: {title: '用户主页'}
    },
    // 用户设置
    {
        name: 'user-setting',
        path: '/member/:username/setting',
        component: () => import('@/views/user/Setting'),
        meta: {title: '设置', requireAuth: true}
    },
    {
        path: "/404",
        name: "404",
        component: () => import("@/views/error/404"),
        meta: {title: "404-NotFound"},
    },
    {
        path: "*",
        redirect: "/404",
        hidden: true,
    },
];

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};

const router = new VueRouter({
    routes,
});

export default router;
